home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-17 | 40.2 KB | 1,146 lines | [TEXT/KAHL] |
- /*
- VideoToolbox.h
- This file contains the necessary prototypes for use of all the VideoToolbox
- files except Luminance.c, which has its own header file, Luminance.h, and
- GDInfo.c and GDTestClut.c, which use GDInfo.h.
-
- Precompilation of this header, producing either VideoToolbox.pre or
- VideoToolboxMATLAB.pre, will reduce your compilation time tenfold. See
- VideoToolbox.c or VideoToolboxMATLAB.c for instructions.
-
- Header files whose precompilation depends on the mc68881 or mc68020 THINK C
- compiler options (i.e. math.h and mc68881.h) were omitted from VideoToolbox.h so
- that the resulting precompiled header file can be used in projects regardless of
- those options. (You’ll want them enabled for speed in your lab, but you’ll
- usually want them disabled for portability on the road, e.g. the PowerBook 160
- has no floating point unit.) If you change other options that affect the
- pre-compilation of the headers (e.g. size of double or size of int) you should
- rebuild the precompiled header file, to reflect the new settings.
-
- However, the precompilation _does_ depend on the sizeof(double) and sizeof(int)
- because most functions use or return such values and the external interface must
- allow the appropriate amount of space. THINK C supports a 12-byte "universal"
- format double that works well both with the 68881 fpu (which uses the top two
- bytes and the bottom 8 bytes) and with SANE (which uses the bottom 10 bytes).
- Thus in THINK C it is easy to mix modules compiled with (e.g. your code) and
- without (e.g. the ANSI library) the 68881 option. Unfortunately that excellent
- feature is unique to THINK C. In MPW and Metrowerks C you must use 10-byte
- doubles when you use SANE (i.e. don't use the 68881 fpu), so when you use these
- compilers you'll need separate pre-compiled headers, with and without the 68881
- option, if you want to compile for each environment: to use the 68881 fpu, or
- run on machines that lack it.
-
- Metrowerks project names end in "µ", and indicate which cpu they support by
- "68k" or "ppc". THINK C projects support only the 68k and have names ending in
- "π".
-
- My naming convention for pre-compiled headers indicates the size of int, "2i" or
- "4i", and, if the 68881 is required, "881". Metrowerks pre-compiled headers
- indicate which cpu they support by "68k" or "ppc"; THINK C supports only the
- 68k. The THINK C pre-compiled header that I use is "VideoToolbox.pre", which
- uses 2-byte ints and "universal" 12-byte doubles that work with or without the
- 68881. (The THINK C ANSI library requires 2-byte ints.) The Metrowerks
- CodeWarrior C pre-compiled headers that I use are called,
- "VideoToolbox.68k.4i.pre", "VideoToolbox.68k.4i.881.pre", and
- "VideoToolbox.ppc.pre".
-
- MAC_C:
-
- The Apple Macintosh header files use some extensions to C that are not part of
- Standard C, e.g. "pascal", "short double", enums larger than ints, and function
- prototypes that specify absolute addresses. These keywords and constructions
- cannot be compiled in Standard C. The macro MAC_C is defined as true, below,
- only on Macintosh C compilers that incorporate these extensions, and is false
- otherwise. The MAC_C symbol is used to prevent inclusion of all the
- Macintosh-dependent header files and prototypes when the compiler doesn't
- support them. However, lacking any general test for these extensions, a test
- must be added, below, for each new compiler. At present we test for Symantec's
- THINK C, Apple's MPW C, and Metrowerks CodeWarrior C.
-
- MATLAB:
-
- The VideoToolbox sources can be linked to create a stand-alone C application, or
- a MATLAB external code resource (a "MEX" file), to be invoked by typing the
- function name from within MATLAB. In that case we call the THINK C project a
- "MATLAB project". A MATLAB project must #define the symbol MATLAB as true for
- every C file, must #include the VideoToolbox.h header at the beginning of every
- C file, and must #include MATLABMain.h in the main C file.
-
- Don't #define MATLAB within your C file; use the Edit:Options:THINK C:Prefix
- window instead. E.g. you could type
- #define MATLAB 1
- into the Prefix window, or, more conveniently (because it speeds up your
- compilations enormously), type
- #include "VideoToolboxMATLAB.pre"
- See VideoToolboxMATLAB.c for instructions.
-
- The MATLABMain.h header allocates space for QuickDraw globals for use by THINK C
- MATLAB projects. It should be #included in the main C file of each THINK C
- MATLAB project, i.e. in the C file that contains "main" or "user_fcn". It must
- be included in exactly one source file of each project, as the THINK C Linker
- will otherwise complain.
-
- dgp & dhb.
- Copyright 1989-1994 © Denis G. Pelli
-
- HISTORY: (omitting changes documented in C files)
- 2/20/93 dhb Added various commonly used headers.
- Restructured so that only VideoToolbox.h has to be included,
- whether one is creating stand-alone THINK C or code resources
- to be called by MATLAB. Everything that cares is properly conditioned
- by the symbol MATLAB.
- 7/9/93 dgp Changed our convention for the MATLAB symbol, defining it as
- 1 or 0 instead of defining or leaving undefined. The advantage of
- this approach is that "MATLAB" can now be used as an argument in an
- ordinary if statement, which is much more readable than #if.
- 8/21/93 dhb Added undefs in #if MATLAB so that memory allocation goes through THINK C
- library, not as callback. Callbacks would be OK except that the Mathworks
- forgot to give us one for realloc. This leads to mixing memory managers
- on the same pointers -- bad bad bad.
- 9/2/93 dhb commented out #include <TranslateLinefeeds.h> since it's
- not presently compatible with MATLAB.
- 9/2/93 dgp Moved the NL and NEWLINE macros from Assign.c into this file.
- 9/8/93 dgp Mention VideoToolbox.c.
- 9/11/93 dhb,dgp Define STDIO_INT and STDIO_DOUBLE.
- 9/12/93 dhb Change STDIO_... to PRINTF_... and SCANF_...
- Insert conditional for MATLAB 3.5 vs. 4.x
- 9/14/93 dhb Conditional for MATLAB changed to make symbol match major version number.
- Removed traces of old trying to force 4 byte ints for MATLAB.
- 9/14/93 dgp Moved up inclusion of QuickDraw.h before MATLAB stuff, since cmex.h
- requires it. Fixed typo, changing "#elseif" to "#elif".
- 9/15/93 dgp Edited the comments above, referring to VideoToolbox.c and the new
- VideoToolboxMATLAB.c.
- 9/16/93 dgp Added contents of former Assign.h.
- Defined MAC_C so that the VideoToolbox.h header may be used with
- Standard C.
- 9/16/93 dhb Removed prototype for obsolete GetDateTimeString.
- 10/2/93 dgp Added #include <Errors.h>.
- 12/1/93 dgp Now always write "MATLAB" in all caps, since that's the trademarked name.
- 12/16/93 dhb Somewhere things got munged. Conditional for MATLAB version appeared
- before inclusion of cmex, which won't work. I fixed the order.
- 12/16/93 dhb Commented out inclusion of TranslateLineFeeds.h down below. This
- generates a link error from MATLAB.
- 12/29/93 dgp added #include <Packages.h>
- 6/12/94 dgp added definition of Apple's new BlockMoveData, for compatibility with
- Apple's old pre-Universal header files.
- 6/12/94 dgp #include Strings.h if Universal header files are used.
- 7/28/94 dgp Added test for Metrowerks CodeWarrior C.
- 9/2/94 dgp #include MacMemory.h
- 9/5/94 dgp changed "int" to "short int" in definitions of PRINTF_INT and SCANF_INT for
- MATLAB 4. This is based on common sense, not testing or detailed knowledge.
- */
- #pragma once /* suppress multiple inclusions of this file */
- #ifndef _VIDEOTOOLBOX_ /* suppress multiple inclusions of this file */
- #define _VIDEOTOOLBOX_
- /*
- Header files that are required for successful compilation of the rest of this
- file are marked "required".
- */
- #if THINK_C /* THINK C */ \
- || applec /* MPW C, presumably with Mac extensions */\
- || __MWERKS__ /* Metrowerks CodeWarrior C, " */
- #if THINK_C
- #if __option(thinkc)
- #define MAC_C 1 /* allow Macintosh C extensions: "pascal", "short double", etc. */
- #else
- #define MAC_C 0 /* Standard C */
- #endif
- #else
- #define MAC_C 1 /* allow Macintosh C extensions: "pascal", "short double", etc. */
- #endif
- #else
- #define MAC_C 0 /* Standard C */
- #endif
- #ifndef SHORT_DOUBLE_OK
- #define SHORT_DOUBLE_OK MAC_C /* "short double" not allowed by Standard C */
- #endif
- #include <stdio.h> /* required */
- #include <stdlib.h>
- #if MAC_C
- #include <Quickdraw.h> /* required */
- #endif
- #ifndef MATLAB
- #define MATLAB 0
- #endif
- #if MATLAB
- /*
- This must come after stdlib.h, stdio.h, and QuickDraw.h and before everything
- else. If MATLAB is true then we include the header file cmex.h. Otherwise we
- define the data types that are normally provided by that header, so that code
- that uses these types may be compiled for use in applications. It must come
- before we test for version 3 or 4. The version 3 cmex.h does not define the
- symbol mex_h; version 4 does. This is what we use to figure out which
- version we are compiling for. Sound complicated? Sigh!
- */
-
- #include <cmex.h>
- // Test for MATLAB 4 or MATLAB 3, and set symbol appropriately.
- #undef MATLAB
- #ifdef mex_h
- #define MATLAB 4
- #else
- #define MATLAB 3
- #endif
- #ifndef MAC_C
- #error "MATLAB requires the Macintosh extensions to C."
- #endif
-
- // Undefine the macros that override memory allocation. MATLAB's implementation
- // doesn't work if you use realloc.
- #undef malloc
- #undef calloc
- #undef free
-
- // Define data types for printf, scanf.
- #if (MATLAB == 4) /* Version 4 */
- typedef short int PRINTF_INT; /* type of arguments to printf et al. */
- typedef long double PRINTF_DOUBLE;
- typedef short int SCANF_INT; /* type of arguments to scanf et al. */
- typedef double SCANF_DOUBLE;
- #elif (MATLAB == 3) /* Version 3.5 */
- typedef long int PRINTF_INT; /* type of arguments to printf et al. */
- typedef double PRINTF_DOUBLE;
- typedef short int SCANF_INT; /* type of arguments to scanf et al. */
- typedef long double SCANF_DOUBLE;
- #endif
- #ifdef THINK_C /* Declare our own QuickDraw globals, allocated by MATLABMain.h */
- extern THINK_C_QD mex_qd;
- #define qd mex_qd
- #else
- #define mex_qd qd
- #endif
- #if defined(MAIN) /* Some old programs #define MAIN. */
- #include "MATLABMain.h" /* New programs just #include directly. */
- #endif
- #else
- typedef long int INT;
- #if SHORT_DOUBLE_OK
- typedef short double DOUBLE;/* not allowed by Standard C */
- #endif
- typedef int PRINTF_INT; /* type of arguments to printf et al. */
- typedef double PRINTF_DOUBLE;
- typedef int SCANF_INT; /* type of arguments to scanf et al. */
- typedef double SCANF_DOUBLE;
- #if SHORT_DOUBLE_OK
- typedef struct {
- char *name;
- INT type;
- INT m;
- INT n;
- DOUBLE *pr;
- DOUBLE *pi;
- } Matrix;
- #endif
- #endif
-
- /* Standard C headers */
- #include <ctype.h>
- #include <float.h>
- #include <limits.h>
- #include <string.h>
- #include <time.h>
-
- /* Macintosh headers */
- /*
- The inclusion, above, of Quickdraw.h will result in the inclusion of MixedMode.h
- only if the Universal Headers are used, since the Universal Headers and the Mixed
- Mode Manager are both new, providing universal support for 68k and ppc Macs.
- */
- #if defined(__MIXEDMODE__)
- #define UNIVERSAL_HEADERS 1
- #else
- #define UNIVERSAL_HEADERS 0
- #endif
- #if MAC_C
- #if THINK_C
- #include <console.h>
- #endif
- #include <Devices.h>
- #include <Errors.h>
- #include <Events.h>
- #include <FixMath.h> /* Must come before mc68881.h */
- #include <Fonts.h>
- #include <GestaltEqu.h>
- #include <Memory.h>
- #include <OSEvents.h>
- #include <OSUtils.h> /* required */
- #include <Packages.h>
- #include <Palettes.h>
- #if THINK_C
- #include <profile.h>/* only needed if you want timing info */
- #endif
- #include <QDOffscreen.h>
- #include <Resources.h>
- #include <Retrace.h> /* required */
- #include <Slots.h>
- #include <Sound.h>
- #if !defined(THINK_C) || UNIVERSAL_HEADERS
- #include <Strings.h>/* c2pstr() and p2cstr() */
- #define CtoPstr c2pstr
- #define PtoCstr p2cstr
- #else
- #include <pascal.h> /* CtoPStr() and PtoCStr() */
- #ifndef c2pstr
- #define c2pstr(s) CtoPstr(s)
- #define p2cstr(s) PtoCstr(s)
- #endif
- #endif
- #include <Timer.h> /* required */
- #include <ToolUtils.h>
- #include <Video.h>
- #include <Windows.h> /* required */
- // Old Memory.h header files, before Apple's Universal Headers, don't define the new
- // BlockMoveData(), so we do it here, to retain compability with the old header files.
- #if !UNIVERSAL_HEADERS
- #pragma parameter BlockMoveData(__A0,__A1,__D0)
- extern pascal void BlockMoveData(const void *srcPtr,void *destPtr,Size byteCount)=0xA22E;
- #endif
- #endif
-
- /*
- This redefines the standard C functions, malloc, etc. to instead call Apple's
- corresponding routines, e.g. NewPtr. The THINK C memory management routines are
- poor because they are bad about freeing space, tending to fragment the free space.
- */
- #if THINK_C
- #include "MacMemory.h"
- #endif
-
- /*
- MATLAB AND THE NEWLINE CHARACTER
- In most C environments the newline character is '\n' (ascii 10). In Apple's
- wisdom they chose to separate lines in Macintosh files with the ascii 13
- character, which is usually called the return character '\r'. Standard C
- specifies that the stdio library will use '\n' as the newline character. This
- potentially creates a compatibility problem between Mac C programs and C
- programs written for the rest of the world's computers, since one wants any text
- files they produce to be appropriate to the local environment. Both MPW and
- THINK C resolve the problem behind the scenes, but they do it in different ways.
- MPW redefines the association between symbolic names and character codes, making
- '\n' be 13 and '\r' be 10. THINK C instead modifies the stdio library so that
- reads and writes to a "text" (i.e. not binary) stream are translated, exchanging
- character codes 10 and 13. Both solutions work. However, when we use THINK C to
- create code resources for MATLAB we are forced to use the MPW stdio library that
- is built into MATLAB. Unfortunately this bypasses both compilers' fixes to the
- newline problem. The problem affects every single text i/o operation, e.g. every
- printf and scanf. Alas, there is no way to get the pre-processor to redefine /n
- and /r.
-
- We have attempted two solutions: a quick fix, using macros NL and NEWLINE, and a
- complete clean fix, using TranslateLinefeeds.c. At present only the quick fix
- works.
-
- Our quick fix is to create a macro called NL that is normally defined as the
- newline string "\n", but which is instead defined as "\015" (i.e. ascii 13) when
- MATLAB is true. Programs such as Assign.c that have replaced all instances of
- "\n" by NL will then work whether or not MATLAB is true. The obvious drawback is
- that this quick solution requires these modifications to the source files.
-
- The clean relatively complete solution is to insert a filter,
- TranslateLinefeeds.c, that intercepts the calls to the stdio library and
- translates /r to /n and vice versa for i/o to text files. The header file
- TranslateLinefeeds.h redefines all the stdio calls as macros that call
- corresponding routines within TranslateLinefeeds.c. Note that scanf is not
- intercepted and that for printf (and fprintf, ...) only the format string
- is translated; linefeeds hiding in char or string arguments in the variable
- part of the argument list are not be translated.
- */
- #if MATLAB && THINK_C /* Clean, relatively complete solution */
- //#include <TranslateLinefeeds.h>
- #endif
- #if !defined(_TranslateLinefeeds_) && MATLAB && THINK_C /* Quick fix */
- #define NL "\r"
- #define NEWLINE '\r'
- #else
- #define NL "\n" /* the standard new-line string */
- #define NEWLINE '\n'
- #endif
-
- /*
- TRUE and FALSE
- */
- #ifndef TRUE
- #define FALSE 0
- #define TRUE 1
- #endif
-
- /*
- NAN & INF
- If you're using NAN and INF you'll be interested in the IsNan(), IsInf(), and
- IsFinite() definitions & prototypes below. When compiling for a PowerPC,
- math.h includes the fp.h header, which defines INFINITY and NAN.
- */
- #if !defined(INF)
- #define INF HUGE_VAL /* defined in math.h */
- #endif
- #if !defined(NAN) && !defined(powerc)
- // #define NAN (0.0/0.0) /* evaluated at runtime */
- #define NAN Nan /* global defined in Nan.c */
- #endif
-
- /*
- NUMERICAL CONSTANTS
- It's sad to say, but THINK C 5.02 loses two bits of precision converting between
- doubles and ascii text, in either direction. Thus you will obtain more accurate
- results by computing the numerical constants below at runtime rather than using
- these predefined constants. The ANSI Numerical C Extensions group is moving to
- require C compilers to preserve precision, so there is hope for the future. Of
- course most applications would never notice a loss of two bits precision out of
- the total double precision given by the 64 bits in the mantissa.
- */
- #if !defined(PI)
- #define PI 3.1415926535897932385 /* computed in Mathematica */
- #endif
- #if !defined(LOGPI)
- #define LOGPI 1.14472988584940017414 /* computed in Mathematica */
- #endif
- #if !defined(LOG2)
- #define LOG2 0.69314718055994530942 /* computed in Mathematica */
- #endif
- #if !defined(LOG10)
- #define LOG10 2.30258509299404568402 /* computed in Mathematica */
- #endif
-
- #if MAC_C
- /*
- CLUTSIZE
- Inline code that returns the same answer as GDClutSize(device).
- */
- #define GDCLUTSIZE(device) (gdClutSizeTable[(**(**(device)).gdPMap).pixelSize])
-
- /* Commented out, because its answer is misleading when in 16-bit or 32-bit mode. */
- /* #define GDCOLORS(device) ((**(**(**device).gdPMap).pmTable).ctSize+1) */
- #endif
-
- /*
- FIXED POINT ARITHMETIC
- Apple defines a handy data type called Fixed that is stored in a long, but is
- assumed to have a decimal point in the middle. Many operations, e.g. adding two
- Fixed numbers or multiplying or dividing a Fixed by an integer, can be performed
- directly. To multiply or divide two Fixed numbers use Apple's FixMul() and
- FixDiv(). FixRatio(n,m) returns the Fixed ratio of two integers. Macintosh C
- compilers define double in various ways, depending on whether a floating point
- unit is to be used. The Apple-provided routines for doing type conversion to and
- from Fixed are only appropriate if you are NOT using the floating point unit.
- The ones defined below are faster and work with or without the FPU.
- */
- #define LongToFix(x) ((long)(x)<<16)
- #define FixToLong(x) ((x)>>16)
- #define DoubleToFix(x) ((long)((x)*65536.+0.5))
- #define FixToDouble(x) ((double)(x)*(1./65536.))
-
- #if MAC_C
- /*
- STACK
- StackGrow(n) increases the stack allocation by n bytes. You'll also want to use
- Apple's StackSpace(), declared in Memory.h, that returns the number of bytes
- allocated for the stack.
- */
- #define StackGrow(extraBytes) SetApplLimit(GetApplLimit()-(extraBytes))
- #endif
-
- /* Assign.c */
-
- #define ASSIGN_DIMS 3 /* Feel free to increase or decrease ASSIGN_DIMS. */
- typedef struct {
- short type;
- unsigned sizedOnce:1; /* dim[] is meaningful */
- unsigned sized:1; /* dim[] is final */
- unsigned malloced:1; /* allocated by malloc */
- char *name;
- void *ptr; /* for array, address of element zero */
- long dim[ASSIGN_DIMS]; /* zero indicates a scalar */
- long firstElement; /* for 1-d array, index of first array element. Usually 0 */
- const char *comment; /* text string, or NULL */
- } Description;
- enum{assignReportUnknown=1,assignNoHexInts=2,assignHexFloats=4
- ,assignNoComment=8,assignNoPrintfExit=0x10
- ,assignEchoAssignments=0x20,assignEchoComments=0x40,assignEchoFile=0x80
- };
- enum {assignMemoryError=-1,assignTypeError=-2
- ,assignVariableError=-3,assignUnknownVariableError=-4
- ,assignSubscriptError=-5,assignSubscriptBoundsError=-6
- ,assignEqualsError=-7,assignConstantError=-8,assignHexError=-9
- ,assignSemicolonError=-10,assignFileError=-11
- ,assignInconsistentDescriptionsError=-12,assignUnequalDataError=-13
- ,assignInconsistentDimensionsError=-14
- ,assignCouldntFindDescription=-15
- };
- enum{charType=1,unsignedCharType,shortType,unsignedShortType
- ,longType,unsignedLongType
- ,floatType
- #if SHORT_DOUBLE_OK
- ,shortDoubleType
- #endif
- ,doubleType
- ,charPtrType,unsignedCharPtrType,shortPtrType,unsignedShortPtrType
- ,longPtrType,unsignedLongPtrType
- ,floatPtrType
- #if SHORT_DOUBLE_OK
- ,shortDoublePtrType
- #endif
- ,doublePtrType
- ,stringType,unknownType
- };
- FILE *OpenCalFileRead(char *filename);
- FILE *OpenCalFileReadAndCheck(char *filename);
- FILE *OpenCalFileWrite(char *filename);
- void AppendDescriptions(Description **d,Description *s);
- void CopyDescriptions(Description *d,Description *s);
- Description *AllocateDescriptions(long n);
- void FreeDescriptions(Description *d);
- long NumberOfDescriptions(Description *d);
- Description NullDescription(void);
- int IsNullDescription(Description d);
- #define IsNullDescription(d) ((d).type==0)
- int AssignmentLineWasBlank(void);
- int UnequalDescribedVars(Description d1[],Description d2[],short flags);
- int UnequalDescribedVarPair(Description *d1,Description *d2,short flags);
- int CopyDescribedVars(Description d1[],Description d2[],short flags);
- int CopyDescribedVarPair(Description *d1,Description *d2,short flags);
- long InitializeADescribedVar(Description *d,short flags);
- long InitializeDescribedVars(Description d[],short flags);
- long FindDescribedDim(Description d[],void *ptr,int i,short flags);
- long FindDescription(Description d[],void *ptr,short flags);
- void FreeADescribedVar(Description *d,short flags);
- void FreeDescribedPtrVars(Description d[],short flags);
- void FreeDescribedVars(Description d[],short flags);
- void KeepDescribedVars(Description d[],short flags);
- void KeepADescribedVar(Description *d,short flags);
- long PrintAnAssignment(FILE *stream,Description *d,short flags);
- long PrintAssignments(FILE *stream,Description d[],short flags);
- long PrintAssignmentsToFile(const char *filename,Description d[],short flags);
- long ReadAssignmentLine(FILE *stream,Description d[],short flags);
- long ReadAssignmentBlock(FILE *stream,Description d[],short flags);
- long ReadAssignmentStream(FILE *stream,Description d[],short flags);
- long ReadAssignmentFile(const char *filename,Description d[],short flags);
- Description Describe(short type,void *ptr,char *name,const char *comment);
- Description DescribeArray(short type,void *ptr,char *name,const char *comment,...);
- Description DescribeFirstLast(short type,void *ptr,char *name
- ,const char *comment,long firstElement,long lastElement);
-
- /* Binomial.c */
-
- long BinomialSample(double p,long n);
- int BinomialSampleQuickly(int n);
- double BinomialLowerBound(double P,long k,long n);
- double BinomialUpperBound(double P,long k,long n);
- double BinomialPdf(double p,long k,long n);
- double Binomial(double p,long k,long n);
- double IncompleteBeta(double x,double a,double b);
- double InverseBinomial(double P,long k,long n);
- double InverseIncompleteBeta(double p,double a,double b);
-
- /* BreakLines.c */
-
- char *BreakLines(char *string,long lineLength);
- void PrintWrappedText(FILE *stream,const char *s);
- void PrintWrappedTextToFile(const char *filename,const char *s);
- void PrintWrappedComment(FILE *stream,const char *s);
- void PrintWrappedCommentToFile(const char *filename,const char *s);
-
- #if MAC_C
- /* CardSlot.c */
-
- OSErr CardSlot(char *cardName);
-
- /* CenterRectInRect.c */
-
- void CenterRectInRect(Rect *moveableRectPtr,Rect *fixedRectPtr);
- void OffsetRectTile(Rect *r,int nx,int ny);
- Boolean RectInRect(Rect *r,Rect *R);
- #endif
-
- /* ChiSquare.c */
-
- double PChiSquare (double chiSquare,int n);
-
- /* Choose.c */
-
- #if !MAC_C
- #define Boolean unsigned char
- #endif
- int Choose(int defaultChoice,const char *query,char *choices[],int n);
- char *ChoiceStr(char *choices[],int n);
- int MultipleChoice(short defaultChoice,short n,char *choices[]);
- Boolean YesOrNo(Boolean defaultAnswer);
- extern char *noYes[];
- #if !MAC_C
- #undef Boolean
- #endif
-
- #if MAC_C
- /* ChooseScreen.c */
-
- int ChooseScreen(int screen,const char *question);
-
- /* ConvolveX.c */
-
- void ConvolveX(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
- Rect *srcRectPtr,Rect *dstRectPtr);
-
- /* ConvolveY.c */
-
- void ConvolveY(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
- Rect *srcRectPtr,Rect *dstRectPtr);
-
- /* CopyBitsQuickly.c */
-
- enum{addOverQuickly=40,addOverParallel=40,mulOver};
- int CopyBitsQuickly(BitMap *srcBits,BitMap *dstBits
- ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
-
- /* CopyQuickDrawGlobals.c */
-
- void CopyQuickDrawGlobals(void);
- #define CopyQuickdrawGlobals CopyQuickDrawGlobals /* old spelling */
-
- /* CopyWindows.c */
-
- enum{copyLiterally=0x10000,copyColorize=0x20000};
- enum{srcCopyLiterally=srcCopy+copyLiterally,addOverLiterally=addOver+copyLiterally
- ,addOverParallelLiterally=addOverParallel+copyLiterally
- ,mulOverLiterally=mulOver+copyLiterally};
- int CopyWindows(CWindowPtr srcWindow,CWindowPtr dstWindow
- ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
-
- /* CreateTrialSnds.c */
-
- void CreateTrialSnds(void);
- #endif
-
- /* DatedString.c */
-
- char *DatedString(unsigned long seconds);
-
- #if MAC_C
- /* DrawPrintf.c */
-
- void DrawPrintf(char *s, ...);
- #endif
-
- /* Exponential.c */
-
- double ExponentialPdf(double x);
-
- /* ffprintf.c */
-
- int ffprintf(FILE *stream[2],char *format,...);
-
- #if MAC_C
- /* FlushCacheRange.c */
-
- void FlushCacheRange (void *address, unsigned long count);
-
- /* fp.c */
-
- /* These 3 prototypes appear in Apple's fp.h, but only when it's compiled for */
- /* the PowerPC, not for the 68k. Apple has promised to eventually make the routines */
- /* available on both platforms. In the meantime the VideoToolbox provides the routines */
- /* for 68k machines, so that your programs can use these functions without worrying */
- /* about which platform you might run on. */
- /* Apple's current header files define extended80 in <Types.h>. However, some older */
- /* compilers may have old header files that only define extended80 in <SANE.h>. */
- /* In that case, comment out any offending prototypes below, and paste them */
- /* directly into your source files, after "#include <SANE.h>". The SANE.h header */
- /* file has side effects, so you shouldn't include it here */
- /* or in any file that doesn't really need it. Alternatively, instead of including */
- /* all of SANE.h, you could just copy the definition of extended80. We can't do that */
- /* here because it's an error to repeat a typedef. */
-
- #if !__powerc
- void ldtox80(long double *x,extended80 *x80);
- void x80told(extended80 *x80,long double *x);
- long int fpclassify(double x);
- #endif
-
- /* GDOpenWindow.c */
-
- void AddExplicitPalette(WindowPtr window);
- void RemovePalette(WindowPtr window);
- WindowPtr GDOpenWindow1(GDHandle device);
- void GDDisposeWindow1(WindowPtr window);
- CWindowPtr GDOpenWindow(GDHandle device);
- void GDDisposeWindow(CWindowPtr myWindow);
- void GDGrayColorTable(GDHandle device);
- void SwapWindowExplicitMode(CWindowPtr window,Boolean *explicit);
- BitMap *GetBitMapPtr(CWindowPtr window);
- Boolean IsOffScreen(CWindowPtr window);
- Boolean IsWindow(CWindowPtr window);
-
- /* GDPrintf.c */
-
- void GDPrintf(char *s, ...);
-
- /* GDTime.c */
-
- double GDFrameRate(GDHandle device);
- double GDMovieRate(GDHandle device,int quickly);
- double GDMovieSize(GDHandle device,int quickly);
- double GDVBLRate(GDHandle device);
- double TickRate(void);
- typedef OSErr (*SetEntriesFunction)(GDHandle device,short start,short count
- ,ColorSpec *aTable);
- OSErr GDTimeClut(GDHandle device,SetEntriesFunction function,short clutEntries
- ,double *sPtr,double *framesPtr,double *missingFramesPtr,double *frameRatePtr);
-
- /* GDVideo.c */
-
- #define MAX_SCREENS 8
- char *GDCardName(GDHandle device);
- extern short gdClutSizeTable[33];
- short GDClutSize(GDHandle device);
- long GDColors(GDHandle device);
- OSErr GDControl(int refNum,int csCode,Ptr csParamPtr);
- short GDDacSize(GDHandle device);
- OSErr GDDirectSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
- OSErr GDGetDefaultGamma(GDHandle device,GammaTbl **gammaTbl);
- OSErr GDGetDefaultMode(GDHandle device,short *modePtr);
- OSErr GDGetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
- OSErr GDGetGamma(GDHandle device,GammaTbl **myGammaTblHandle);
- OSErr GDGetGray(GDHandle device,Boolean *flagPtr);
- OSErr GDGetInterrupt(GDHandle device,Boolean *flagPtr);
- OSErr GDGetMode(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
- OSErr GDGetPageBase(GDHandle device,short page,Ptr *baseAddrPtr);
- OSErr GDGetPageCnt(GDHandle device,short mode,short *pagesPtr);
- OSErr GDGrayPage(GDHandle device,short page);
- Boolean GDHasMode(GDHandle device,short mode,short *pixelSizePtr,short *pagesPtr);
- #define GDLinearGamma GDUncorrectedGamma /* old name, before 12/16/92 */
- short GDModePixelSize(GDHandle device,short mode);
- unsigned char *GDName(GDHandle device);
- char *GDNameStr(GDHandle device);
- ColorSpec *GDNewLinearColorTable(GDHandle device);
- short GDPixelSize(GDHandle device);
- OSErr GDPrintGammaTable(FILE *o,GDHandle device);
- OSErr GDReset(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
- OSErr GDRestoreDeviceClut(GDHandle device);
- OSErr GDRestoreGamma(GDHandle device);
- OSErr GDSaveGamma(GDHandle device);
- OSErr GDSetDefaultMode(GDHandle device,short mode);
- OSErr GDSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
- OSErr GDSetEntriesByType(GDHandle device,short start,short count,ColorSpec *table);
- OSErr GDSetEntriesByTypeHighPriority(GDHandle device,short start,short count
- ,ColorSpec *table);
- OSErr GDSetGamma(GDHandle device,GammaTbl *myGammaTblPtr);
- OSErr GDSetGray(GDHandle device,Boolean flag);
- OSErr GDSetInterrupt(GDHandle device,Boolean flag);
- OSErr GDSetMode(GDHandle device,short mode,short page,Ptr *baseAddrPtr);
- OSErr GDSetPageDrawn(GDHandle device,short page);
- OSErr GDSetPageShown(GDHandle device,short page);
- OSErr GDStatus(int refNum,int csCode,Ptr csParamPtr);
- short GDType(GDHandle device);
- OSErr GDUncorrectedGamma(GDHandle device);
- int GDVersion(GDHandle device);
- #define ModeName GDModeName /* old name, before 1/18/93 */
- int PatchMacIIciVideoDriver(void);
-
- /* GetClicks.c */
-
- short GetClicks(void);
- #endif
-
- /* GetTimeDateString.c */
-
- char *GetTimeDateString(time_t t);
-
- #if MAC_C
- /* GetVersionString.c */
-
- char *GetVersionString(void);
-
- /* GetScreenDevice.c */
-
- GDHandle GetScreenDevice(int n);
- int GetScreenIndex(GDHandle device);
- GDHandle SlotToScreenDevice(int n);
- short int GetDeviceSlot(GDHandle device);
- GDHandle GetWindowDevice(WindowPtr theWindow);
- GDHandle GetRectDevice(Rect *r);
- void LocalToGlobalRect(Rect *r);
- void GlobalToLocalRect(Rect *r);
-
- /* GetVoltage.c */
-
- double VoltsDuringFrame(double frames);
- double GetVoltage(short channel,double *gainPtr,double *frequencyPtr,long n
- ,double *sdPtr);
- short GetVoltages(short channel,double *gainPtr,double *frequencyPtr,long *nPtr
- ,unsigned short readings[],double *voltDeltaPtr,double *voltZeroPtr);
- short InitiateVoltageSampling(short channel,double *gainPtr,double *frequencyPtr
- ,double *voltDeltaPtr,double *voltZeroPtr);
- short RetrieveVoltages(long *nPtr,unsigned short readings[]);
- int ForeRunnerSlot(void);
- enum{voltageBufferOverflow=1<<0,voltageOverflow=1<<1,voltageUnderflow=1<<2};
- #endif
-
- /* HexToBinary.c */
-
- int HexToBinary(char *string,void *ptr);
- char *BinaryToHex(size_t n,void *ptr,char *string);
-
- #if MAC_C
- /* HideMenuBar.c */
-
- void HideMenuBar(void);
- void ShowMenuBar(void);
- void SquareCorners(GDHandle device);
- void RestoreCorners(GDHandle device);
- void UnclipScreen(GDHandle device);
- void RestoreScreenClipping(GDHandle device);
-
- /* Identify.c */
-
- char *IdentifyApplication(void);
- char *IdentifyCompiler(void);
- char *IdentifyMachine(void);
- char *IdentifyModel(void);
- char *IdentifyOwner(void);
- char *IdentifyVideo(GDHandle device);
-
- /* ImageStatistics */
-
- double ImageEnergy(GWorldPtr aWorld,Rect *aRect,double background);
- void ImageStatistics(GWorldPtr world,Rect *rect
- ,long *minPtr,long *maxPtr,double *meanPtr,double *meanSquarePtr);
-
- /* IsCmdPeriod.c */
-
- Boolean IsCmdPeriod(EventRecord *event);
- #endif
-
- /* IsNan.c */
-
- int IsNan(double x);
- int IsInf(double x);
- #ifndef IsFinite /* neither NAN nor ±INF */
- #define IsFinite(x) \
- (sizeof(x)>8? \
- ((*(short *)&(x) & 0x7FFF)!=0x7FFF) /* 10 or 12 byte double */\
- :((*(short *)&(x) & 0x7FF0)!=0x7FF0)) /* 8 byte double */
- #endif
-
- #if MAC_C
- /* kbhit.c */
-
- int kbhit(void);
- int getcharUnbuffered(void);
- #endif
-
- /* Log2L.c */
-
- long Log2L(unsigned long j);
-
- #if MAC_C
- /* MakeNoise.c */
-
- int FillWindowWithNoise(CWindowPtr window,double dx,double dy,Boolean randomPhase);
- int MakeNoise1(double dx,double dy,Boolean randomPhase,PixMap *frame);
-
- /* MaximizeConsoleHeight.c */
-
- void MaximizeConsoleHeight(void);
- #endif
-
- /* Mean.c */
-
- double Mean(double x[],long n,double *sdPtr);
- double MeanF(float x[],long n,double *sdPtr);
- double MeanB(char x[],long n,double *sdPtr);
- double MeanUB(unsigned char x[],long n,double *sdPtr);
- double MeanW(short x[],long n,double *sdPtr);
- double MeanUW(unsigned short x[],long n,double *sdPtr);
- double MeanL(long x[],long n,double *sdPtr);
- double MeanUL(unsigned long x[],long n,double *sdPtr);
-
- /* Nan.c */
- extern const short __NAN[];
- #define Nan (*(double *)__NAN)
-
- /* Normal.c */
-
- double NormalPdf(double x);
- double Normal(double x);
- double InverseNormal(double p);
- double NormalSample(void);
- double Normal2DPdf(double r);
- double Normal2D(double r);
- double InverseNormal2D(double p);
- double Normal2DSample(void);
- double InverseNormal2DPdf(double p);
- void BoundedNormalIntegers(short *distribution,long n,double mean,double sd
- ,short min,short max);
-
- /* nrand.c */
-
- unsigned long nrand(unsigned long n);
-
- /* OpenDataFiles.c */
-
- unsigned long OpenDataFiles(FILE **inPtr,FILE **outPtr
- ,char *inName,char *outName);
-
- /* OpenPreferencesFolder.c */
-
- #if !MAC_C
- #define OSErr short
- #endif
- OSErr OpenPreferencesFolder(void);
- OSErr ClosePreferencesFolder(void);
- OSErr OpenPreferencesWD(short *wdRefNumPtr);
- #if !MAC_C
- #undef OSErr
- #endif
-
- #if MAC_C
- /* PixMapToPICT.c */
-
- void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
- ,int pixelSize,ColorTable **cTable);
-
- /* PixMapToPostScript.c */
-
- void WindowToEPS(CWindowPtr window,char *filename,Rect *rectPtr
- ,Rect *pageRectPtr,double cellsPerInch,int grayLevels,float reflectance[256]);
- void PixMapToEPS(char *filename,PixMap **pm,Rect *rectPtr
- ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
- void PixMapToPostScript(char *filename,PixMap **pm,Rect *rectPtr
- ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
- void AppendToFile(char *filename,char *string);
-
- /* PlotXY.c */
-
- typedef struct{
- Boolean continuing; /* zero to start a new curve */
- long color; /* e.g. blackColor, blueColor */
- short lineWidth; /* in pixels, zero for none */
- short symbolWidth; /* in pixels, zero for none */
- short dashOffset; /* in pixels */
- short dash[5]; /* in pixels. The array is terminated by a zero element */
- short h,v; /* reserved for internal use */
- Fixed pathLengthF; /* reserved for internal use */
- } PlotXYStyle;
- void PlotXY(WindowPtr window,double x,double y,PlotXYStyle *style);
- #endif
-
- /* PrintfExit.c */
-
- int PrintfExit(const char *format,...);
-
- #if MAC_C
-
- /* PrintfGWorld.c */
-
- void PrintfGWorld(GWorldPtr our);
- void PrintStringAsBitmap(unsigned char *s);
-
- /* QD32Exists.c */
-
- Boolean QD8Exists(void);
- Boolean QD32Exists(void);
- Boolean NewPaletteManager(void);
- #endif
-
- /* randU.c */
-
- unsigned short randU(void);
- unsigned long randUL(void);
- void srandU(unsigned n);
- void RandFill(void *address,long bytes);
-
- /* ReadMATLABFile.c */
-
- int LoadNamedMatIntoDoubles(FILE *f,const char *name,long *rows,long *cols
- ,double **real,double **imag);
- int LoadNamedMatIntoShorts(FILE *f,const char *name,long *rows,long *cols
- ,short **real,short **imag);
- int LoadNextMatIntoDoubles(FILE *f,char *name,long *rows,long *cols
- ,double **real,double **imag);
- int LoadNextMatIntoShorts(FILE *f,char *name,long *rows,long *cols
- ,short **real,short **imag);
- int SaveMatDoubles(FILE *f,char *name,long rows,long cols,double *real,double *imag);
- int SaveMatShorts(FILE *f,char *name,long rows,long cols,short *real,short *imag);
-
- #if MAC_C
- /* RectToAddress.c */
-
- unsigned char *RectToAddress(PixMap *pixMapPtr,Rect *rectPtr,short *rowBytesPtr,
- short *pixelSizePtr,short *bitsOffsetPtr);
- Ptr GetPixBaseAddr32(PixMap **pm);
- #endif
-
- /* Require.c */
-
- void Require(long quickDrawVersion);
- struct PrecompileSizeofInt{
- int i;
- };
- struct PrecompileSizeofDouble{
- double d;
- };
-
- #if MAC_C
- /* RestoreCluts.c */
-
- void RestoreCluts(void);
-
- /* SetEntriesQuickly.c */
-
- OSErr SetEntriesQuickly(GDHandle device,short start,short count,ColorSpec *table);
- short macltset(GDHandle device,register short start
- ,unsigned short *red,unsigned short *green,unsigned short *blue,short count1);
- short GetCardType(GDHandle device);
- char *GetCardBase(GDHandle device);
- OSErr WaitForNextBlanking(GDHandle device);
-
- /* SetFileInfo.c */
-
- void SetFileInfo(char *fileName,OSType fileType,OSType fileCreator);
-
- /* SetMouse.c */
-
- void SetMouse(Point where);
-
- /* SetOnePixel.c */
-
- void SetPixmapPixel(PixMap *pmHandle,int x,int y,unsigned long value);
- unsigned long GetPixmapPixel(PixMap *pmHandle,int x,int y);
- unsigned char *GetPixmapPixelAddress(PixMap *pmHandle,int x,int y);
- void SetDevicePixel(GDHandle device,int x,int y,unsigned long value);
- unsigned long GetDevicePixel(GDHandle device,int x,int y);
- void SetOnePixel(int x,int y,unsigned long value);
- unsigned long GetOnePixel(int x,int y);
- #define SetIPixel SetDevicePixel /* So that old programs won't break. */
- #define GetIPixel GetDevicePixel /* So that old programs won't break. */
-
- /* SetPixelsQuickly.c */
-
- int SetPixelsQuickly(int x,int y,unsigned long value[],short n);
- int GetPixelsQuickly(int x,int y,unsigned long value[],short n);
- int SetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
- int GetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
- int SetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
- int GetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
- int SetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
- int GetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
-
- /* SetPriority.c */
-
- void SwapPriority(char *priority);
- void SetPriority(int i);
- int GetPriority(void);
- #endif
-
- /* Shuffle.c */
-
- void Shuffle(void *array,long elements,size_t elementSize);
-
- #if MAC_C
- /* SndPlay1.c */
-
- OSErr SndPlay1(Handle snd);
- void SndStop1(void);
- short SndDone1(void);
-
- /* StringToDateAndSecs.c */
-
- double StringToDateAndSecs(char *string,DateTimeRec *date);
-
- /* StringBounds.c */
-
- void CharBounds(char a,Rect *bounds,long *count);
- void StringBounds(const unsigned char *s,Rect *bounds,long *count);
- void StrBounds(char *s,Rect *bounds,long *count);
-
- /* Timer.c */
-
- struct Timer{
- TMTask time;
- long ourA5;
- long interval,elapsed,elapsedIntervals;
- long timeToStartTimer; /* minimum time in µs */
- long stopDelay; /* µs from call to stop, re from call to start */
- long timeManagerVersion;
- struct Timer *next,*previous; /* doubly linked list of Timers */
- };
- typedef struct Timer Timer;
-
- Timer *NewTimer(void);
- void DisposeTimer(Timer *t);
- void StartTimer(Timer *t);
- long StopTimer(Timer *t); /* µs */
- double StopTimerSecs(Timer *t); /* s */
- long PeekTimer(Timer *t); /* µs */
- double PeekTimerSecs(Timer *t); /* s */
-
- /* TitleBarHeight.c */
-
- int TitleBarHeight(WindowPtr window);
-
- /* TrapAvailable.c */
-
- Boolean TrapAvailable(short theTrap);
- #endif
-
- /* Uniform.c */
-
- double UniformSample(void);
-
- #if MAC_C
- /* VBLInstall.c */
-
- struct VBLTaskAndA5 {
- volatile VBLTask vbl;
- long ourA5;
- #if USESROUTINEDESCRIPTORS
- UniversalProcPtr subroutine;
- #else
- void (*subroutine)(struct VBLTaskAndA5 *vblData);
- #endif
- GDHandle device;
- long slot;
- volatile long newFrame; /* Boolean */
- volatile long frame; // count up from zero
- volatile long framesLeft; /* count down to zero */
- long framesDesired;
- Timer *frameTimer; /* time ms since last VBL interrupt, see Timer.c */
- void *ptr; /* use this for whatever you want */
- };
- typedef struct VBLTaskAndA5 VBLTaskAndA5;
- OSErr VBLInstall(VBLTaskAndA5 *vblData,GDHandle device,long frames);
- OSErr VBLRemove(VBLTaskAndA5 *vblData);
- void SimpleVBLSubroutine(VBLTaskAndA5 *vblData);
-
- /* VideoTFB.c */
-
- Boolean TFBInSlot(int slot);
- void SetUpTFB(int slot);
- void RampClutTFB(int slot);
- void GrayClutTFB(int slot);
- void LoadClutTFB(int slot,unsigned char rgb[256][3]);
- void NewBlankingTFB(int slot);
- void NewFieldTFB(int slot);
- int BlankingTFB(int slot);
- void SetDepthTFB(int slot,short int bits);
- void SynchSetDepthTFB(int masterSlot,int slot,short int bits);
- void SynchToMainDeviceTFB(GDHandle device);
- void HaltTFB(int slot);
- void RestartTFB(int slot,short int bits);
- void HaltDeviceTFB(GDHandle device);
- void RestartDeviceTFB(GDHandle device);
- void ScrollTFB(int slot,short int bits,long x,long y);
- void PanTFB(int slot,long int x);
- #endif
-
- /* VLambda.c */
-
- double VLambda(double nm);
- double VLambdaPrime(double nm);
-
- #if MAC_C
- /* Zoom.c */
-
- void Zoom(WindowPtr theWindow,int zoomDir,EventRecord *event);
- #endif
-
- #endif /* _VIDEOTOOLBOX_ */
-